import math
class Solution(object):
    def fractionAddition(self, expression):
        self.base = [0, 1, 0]
        last_op = 0
        if expression[0] == '-':
            last_op = 1
            expression = expression[1:]
        left = 0
        right = 0
        n = len(expression)

        def search(p, q, op):
            if self.base[2] == 0:
                fenzi1 = self.base[0] * q
            else:
                fenzi1 = - self.base[0] * q
            if op == 0:
                fenzi2 = p * self.base[1]
            else:
                fenzi2 = - p * self.base[1]
            self.base[1] *= q
            fenzi = fenzi1 + fenzi2
            if fenzi == 0:
                self.base = [0, 1, 0]
            else:
                if fenzi < 0:
                    self.base[2] = 1
                    fenzi = - fenzi
                else:
                    self.base[2] = 0
                gcd = math.gcd(fenzi, self.base[1])
                self.base[0] = fenzi // gcd
                self.base[1] //= gcd

        while right < n:
            if expression[right] in {'+', '-'}:
                num = expression[left: right]
                k = num.find('/')
                search(int(num[:k]), int(num[k + 1:]), last_op)
                if expression[right] == '+':
                    last_op = 0
                else:
                    last_op = 1
                left = right + 1
            right += 1
        num = expression[left: right]
        k = num.find('/')
        search(int(num[:k]), int(num[k + 1:]), last_op)
        if self.base[2] == 1:
            t = '-'
        else:
            t = ''
        t += str(self.base[0]) + '/' + str(self.base[1])
        return t

data = Solution()
expression = "-1/2+1/2"
print(data.fractionAddition(expression))